package com.mioto.ld.module.device.controller.app;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mioto.ld.component.BasePager;
import com.mioto.ld.module.device.model.app.AppDeviceListVO;
import com.mioto.ld.module.device.model.app.AppDeviceMainPageAddressVO;
import com.mioto.ld.module.device.model.app.AppDeviceMainPageCounterVO;
import com.mioto.ld.module.device.model.app.AppDeviceMainPageVO;
import com.mioto.ld.module.device.service.IDeviceService;
import com.mioto.ld.result.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author mioto-qinxj
 * @date 2024/6/8
 * @desc
 */
@RestController
@RequestMapping("/app/device")
@Api(tags = "app端设备信息管理")
public class AppDeviceController {
    @Resource
    private IDeviceService deviceService;

    @GetMapping("/mainPage/product")
    @ApiOperation(value="首页产品信息",response = AppDeviceMainPageVO.class)
    public ResultData productData (){
        return ResultData.success(deviceService.findAppMainData());
    }

    @GetMapping("/mainPage/counterAndAddress")
    @ApiOperation(value="首页设备数据集合",response = AppDeviceMainPageCounterVO.class)
    public ResultData deviceData (Integer productId){
        return ResultData.success(deviceService.findAppMainDeviceData(productId));
    }

    @GetMapping("/mainPage/device/list")
    @ApiOperation(value="根据设备id查设备列表",response = AppDeviceListVO.class)
    @ApiImplicitParam(name = "searchType",value = "1-在线设备 2-离线设备")
    public ResultData deviceList (BasePager basePager,int searchType,Integer...  deviceIds){
        PageHelper.startPage(basePager.getPage(), basePager.getRows(), basePager.getSortBy());
        List<AppDeviceListVO> list = deviceService.findAppDeviceList(deviceIds,searchType);
        PageInfo<AppDeviceListVO> pageInfo = new PageInfo<>(list);
        Map<String, Object> result = new HashMap<>(4);
        result.put("count", pageInfo.getTotal());
        result.put("list", pageInfo.getList());
        return ResultData.success(result);
    }

    @GetMapping("/mainPage/appUser/devices")
    @ApiOperation(value="app用户设备集合",response = AppDeviceMainPageAddressVO.class)
    public ResultData appUserDevices (){
        return ResultData.success(deviceService.appUserDevices());
    }
}
